<!-- 分销员管理 -->
<template>
  <div>
    <el-main class="base_main_content">
      <div class="base_screen_header">
        <span></span>
        <el-form :inline="true" class="base_search_form" @submit.prevent>
          <el-form-item>
            <el-input v-model="name" @keyup[native].enter="searchName" @change="searchName" placeholder="姓名"
              :suffix-icon="Search" clearable />
          </el-form-item>
          <el-form-item>
            <el-input v-model="login" @keyup[native].enter="searchLogin" @change="searchLogin" placeholder="账号"
              :suffix-icon="Search" clearable />
          </el-form-item>
        </el-form>
      </div>
      <StatusBar :data="statusList" default="all" />
      <div class="base_main_header">
        <el-button type="primary" text @click="getExport">导出</el-button>
      </div>
      <MemberTable :type="config.type"></MemberTable>
    </el-main>
  </div>
</template>

<script setup>
import StatusBar from "@com/StatusBar.vue";
import MemberTable from '@com/member/MemberTable.vue'

import { ref, reactive } from "vue";
import { Search } from "@element-plus/icons-vue";
import api from "@api/member"
import $ from "@util/base"
import useRoute from "@util/router";

const config = {
  type: 'distributormanager'
}

const route = useRoute();

route.watchRouter(config.type, () => { getNum() })

const statusList = reactive([
  {
    label: "全部",
    value: "all",
    total: 0,
  },
  {
    label: "正常",
    value: "1030001",
    total: 0,
  },
  {
    label: "封禁",
    value: "1030002",
    total: 0,
  },
]);

const name = ref(route.query().name || "");
const login = ref(route.query().login || "");

function searchName(val) {
  route.replaceQuery("name", val);
}
function searchLogin(val) {
  route.replaceQuery("login", val);
}

getNum()
function getNum() {
  let routeQuery = route.query()
  api.num({
    loginName: routeQuery.login,
    nickname: routeQuery.name,
    memberType: "1009002"
  }, val => {
    statusData(val)
  })
}

function statusData(val) {
  statusList.forEach((e, i) => { e.total = val[i] })
}

function getExport() {
  let routeQuery = route.query()
  api.export(config.type, {
    loginName: routeQuery.login,
    nickname: routeQuery.name,
    memberStatus: routeQuery.status,
  }, val => {
    $.download(val.url, "会员列表导出")
  })
}
</script>
